<?php
declare (strict_types = 1);
namespace app\course\model\record\admin;

use app\common\model\BaseModel;
use app\course\logic\base\admin\Course;
use app\user\logic\user\Account;

/**
 * 用户学习记录模型
 */
class LearnCourseFinished extends BaseModel
{
    /**
     * 表名
     * @var string
     */
    protected $name = 'user_learn_course_finished';

    /**
     * 设置自动写入时间
     * @var boolean
     */
    protected $autoWriteTimestamp = true;
    protected $updateTime         = false;
    /**
     * 时间显示格式
     * @var string
     */
    protected $dateFormat = 'Y-m-d H:i';

    /**
     * 定义字段类型
     * @var array
     */
    protected $type = [
        'id' => 'integer',
    ];

    /**
     * 关联的用户信息
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-08-07
     * @return   [type]                         [description]
     */
    public function user()
    {
        return $this
            ->belongsTo(Account::class, 'user_id')
            ->with(['avatar_url'])
            ->removeOption('soft_delete')
            ->removeWhereField('mhm_id');
    }

    /**
     * 关联课程标题
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-08-07
     * @return   [type]                         [description]
     */
    public function course()
    {
        return $this->belongsTo(Course::class, 'course_id')->bind(['course_title' => 'title']);
    }

}
